<?php

namespace App\Models\Ddaman;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Models\common\Base;
use Illuminate\Database\Eloquent\SoftDeletes;

class Branch extends Base
{
    use HasFactory,SoftDeletes;

    protected $table = "sy_branch";

    //const CREATED_AT = null;
    //const UPDATED_AT = null;

    protected $fillable = [
        'guid','title','pid','sort','person_id','description'
    ];


    public $rule = [
        'title' => 'required|string|between:2,100',
    ];

    public $editRule = [
        'id' => 'required',
        'title' => 'required|string|between:2,100',
    ];

    public $message = [
        'id.required' => '标识必须',
        'title.required' => '部门名称必须填写',
    ];

    /*
     * 获取列表
     * */
    public function getList( $param = [] )
    {
        $limit = isset($param['limit']) ? $param['limit'] : 10;
        $where = [];

        if (isset($param['keywords']) && $param['keywords']){
            $keywords = trim($param['keywords']);
            $where[] = ['name','like',"%$keywords%"];
        }

        /*$field = array_merge(['id'],$this->fillable);
        $list = $this->where($where)->orderBy('id','desc')->select($field)->paginate($limit);*/
        $all = Branch::get()->toArray();
        $list = list_to_tree($all,'id','pid');

        return $list;

    }






}
